/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.circle.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.circle.entity.HkMediaCirclePostsCommentReply;
import com.thinkgem.jeesite.modules.hk.circle.service.HkMediaCirclePostsCommentReplyService;

/**
 * 帖子回复Controller
 * @author 罗天文
 * @version 2018-08-03
 */
@Controller
@RequestMapping(value = "${adminPath}/circle/hkMediaCirclePostsCommentReply")
public class HkMediaCirclePostsCommentReplyController extends BaseController {

	@Autowired
	private HkMediaCirclePostsCommentReplyService hkMediaCirclePostsCommentReplyService;
	
	@ModelAttribute
	public HkMediaCirclePostsCommentReply get(@RequestParam(required=false) String id) {
		HkMediaCirclePostsCommentReply entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkMediaCirclePostsCommentReplyService.get(id);
		}
		if (entity == null){
			entity = new HkMediaCirclePostsCommentReply();
		}
		return entity;
	}
	
	@RequiresPermissions("circle:hkMediaCirclePostsCommentReply:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkMediaCirclePostsCommentReply hkMediaCirclePostsCommentReply, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkMediaCirclePostsCommentReply> page = hkMediaCirclePostsCommentReplyService.findPage(new Page<HkMediaCirclePostsCommentReply>(request, response), hkMediaCirclePostsCommentReply); 
		model.addAttribute("page", page);
		return "hk/circle/hkMediaCirclePostsCommentReplyList";
	}

	@RequiresPermissions("circle:hkMediaCirclePostsCommentReply:view")
	@RequestMapping(value = "form")
	public String form(HkMediaCirclePostsCommentReply hkMediaCirclePostsCommentReply, Model model) {
		model.addAttribute("hkMediaCirclePostsCommentReply", hkMediaCirclePostsCommentReply);
		return "hk/circle/hkMediaCirclePostsCommentReplyForm";
	}

	@RequiresPermissions("circle:hkMediaCirclePostsCommentReply:edit")
	@RequestMapping(value = "save")
	public String save(HkMediaCirclePostsCommentReply hkMediaCirclePostsCommentReply, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkMediaCirclePostsCommentReply)){
			return form(hkMediaCirclePostsCommentReply, model);
		}
		hkMediaCirclePostsCommentReplyService.save(hkMediaCirclePostsCommentReply);
		addMessage(redirectAttributes, "保存帖子回复成功");
		return "redirect:"+Global.getAdminPath()+"/circle/hkMediaCirclePostsCommentReply/?repage";
	}
	
	@RequiresPermissions("circle:hkMediaCirclePostsCommentReply:edit")
	@RequestMapping(value = "delete")
	public String delete(HkMediaCirclePostsCommentReply hkMediaCirclePostsCommentReply, RedirectAttributes redirectAttributes) {
		hkMediaCirclePostsCommentReplyService.delete(hkMediaCirclePostsCommentReply);
		addMessage(redirectAttributes, "删除帖子回复成功");
		return "redirect:"+Global.getAdminPath()+"/circle/hkMediaCirclePostsCommentReply/?repage";
	}

}